﻿
Partial Class Controls_MyEntitiesControl
    Inherits System.Web.UI.UserControl

    Dim u As MembershipUser
    Dim personId As Int32
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        u = Membership.GetUser(HttpContext.Current.User.Identity.Name)
        Dim getpersonid As New GetPersonIdFromUserId()
        personId = getpersonid.GetPersonId(CType(u.ProviderUserKey, Guid))
        If GridView1.SelectedValue Is Nothing Then
            Dim entityidTA As New LogginsLogDSTableAdapters.usp_GetEntityListFull_ByPersonIdTableAdapter()
            Dim entityidDT As LogginsLogDS.usp_GetEntityListFull_ByPersonIdDataTable
            entityidDT = entityidTA.GetData(personId)
            'If entityidDT.Rows.Count = 0 Then
            '    Response.Redirect("~/private/RegEntity.aspx")
            'End If
            Dim entityid As Integer = (From entities In entityidDT.AsEnumerable() Select entities).FirstOrDefault().ID
            ObjectDataSource2.SelectParameters("EntityID").DefaultValue = entityid
        Else

        End If
    End Sub

    Protected Sub ObjectDataSource1_Selecting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource1.Selecting
        e.InputParameters("PersonId") = personId
    End Sub

    Protected Sub ObjectDataSource2_Inserted(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource2.Inserted
        Dim insertedid As Integer = CInt(e.OutputParameters("EntityId"))

        Try
            Dim insertpersonentityTA As New LogginsLogDSTableAdapters.usp_PersonEntity_ExpTableAdapter()
            insertpersonentityTA.Insert(personId, insertedid, CType(1, Boolean?))

        Catch ex As Exception
            Throw ex
        End Try
        GridView1.DataBind()
    End Sub

    Protected Sub ObjectDataSource2_Deleting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource2.Deleting
        'Response.Write(FormView1.SelectedValue.ToString())
        Dim personentitypeexpTA As New LogginsLogDSTableAdapters.SPTableAdapter()
        personentitypeexpTA.usp_PersonEntity_ExpDelete_ByPersonEntityId(personId, FormView1.SelectedValue.ToString())
        Dim entityTA As New LogginsLogDSTableAdapters.usp_EntityTableAdapter()
        entityTA.Delete(FormView1.SelectedValue.ToString())

        GridView1.DataBind()

        e.Cancel = True
    End Sub

    Protected Sub ObjectDataSource2_Updated(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource2.Updated
        GridView1.DataBind()
    End Sub

    'Protected Sub FormView1_ModeChanged(sender As Object, e As System.EventArgs) Handles FormView1.ModeChanged
    '    Dim DateCreatedTextBox As TextBox = CType(Me.FormView1.FindControl("DateCreatedTextBox"), TextBox)
    '    Dim EntityTypeIdTextBox As TextBox = CType(Me.FormView1.FindControl("EntityTypeIdTextBox"), TextBox)
    '    Dim ActiveCheckBox As CheckBox = CType(Me.FormView1.FindControl("ActiveCheckBox"), CheckBox)
    '    DateCreatedTextBox.Text = DateTime.Now
    '    EntityTypeIdTextBox.Text = 0
    '    ActiveCheckBox.Checked = True
    'End Sub

    Protected Sub ObjectDataSource2_Inserting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource2.Inserting
        e.InputParameters("DateCreated") = DateTime.Now
        'e.InputParameters("EntityTypeId") = 0
        e.InputParameters("Active") = True

    End Sub
End Class
